package com.share.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.domain.SysRole;
import com.share.domain.SysUserRole;
import com.share.service.SysRoleService;
import com.share.mapper.SysRoleMapper;
import com.share.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
    implements SysRoleService{



    @Autowired
    SysUserRoleService sysUserRoleService;

    public List<SysRole> listRolesByUserId(Long id) {
        List<SysUserRole> sysUserRoles = sysUserRoleService.list(new QueryWrapper<SysUserRole>().eq("user_id", id));
        List<Long> roleIds = sysUserRoles.stream().map(p -> p.getRoleId()).collect(Collectors.toList());
        List<SysRole> roles = listByIds(roleIds);

        return roles;
    }
}




